﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using H2.Streams;

namespace Mystery.SCNR
{
    public class Flock
    {
        public const int Offset = 848;
        public const int ChunkSize = 132;

        public static void UpdateOriginBSP(MapStream map, int scnrOffset, int selectedSBSPIndex)
        {
            int chunkCount = map.ReadReflexiveAt(scnrOffset + Offset);
            int startOffset = (int)map.Position;

            for (int i = 0; i < chunkCount; ++i)
            {
                int chunkStartOffset = startOffset + (i * ChunkSize);
                short originBSP = map.ReadInt16At(chunkStartOffset, false);

                if (originBSP == selectedSBSPIndex)
                    map.WriteAt(chunkStartOffset, (short)0, false);
                if (originBSP == 0)
                    map.WriteAt(chunkStartOffset, (short)selectedSBSPIndex, false);
            }
        }
    }
}
